#include <stdlib.h>
#include <stdio.h>
#include <nds.h>

// common headers
#include "common.h"

// local headers
#include "library.h"	// internal
#include "ivorbiscodec.h"
#include "ivorbisfile.h"

#include "oggdecoder.h"

OggVorbis_File vf;

int assign(FILE *f) {
std->iprintf("?1?");
    if(!f) return 1;

	int ret=ov_open(f, &vf, NULL, 0);
	if(ret) {
		std->iprintf("ret=%d\n", ret);
		return 1;
	}

	return 0;
}

int getInfos(sSInfos *i) { 
std->iprintf("?2?");
	if(!i) return 1;

	vorbis_info *vi=ov_info(&vf,-1);
    if(!vi) return 1;

	i->samplingrate=vi->rate;
	i->channels=vi->channels;
	i->duration=(u32)ov_pcm_total(&vf,-1);

	return 0;
}

int getTags(sSTags *t) {
/* I can't do anything else than this, the ogg comment struct only contains:

typedef struct vorbis_comment{
  char **user_comments;
  int  *comment_lengths;
  int  comments;
  char *vendor;

} vorbis_comment;

so that's a bit.......
*/
	return 1;
}

int setTags(sSTags * t) {
	return 1;
}

int play() {
std->iprintf("?3?");
	return 1;
}

int pause() {
	return 1;
}

int stop() {
	return 1;
}

int seek(s32 r, u8 p) {	// 'r' is the relative position (the unit is the unit of the position variable in sSInfos); 'p' is the start position (START, CUR, END)
	return 1;
}

u32 position2ms(u32 d) {
	return 1;
}

u32 ms2position(u32 d) {
	return 1;
}
      
int deassign() {
	ov_clear(&vf); // this one also closes the file!!

	return 0;
}

